import java.io.BufferedReader;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JSONExample3 extends HttpServlet{
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) 
		throws IOException, ServletException {
		request.setCharacterEncoding("UTF-8");
		
		String json = readJSONStringFromRequestBody(request);
		json = json.replaceAll("AUDIO", "AODI");
		json = json.replaceAll("BMW", "BAOMA");
		json = json.replaceAll("TOYOTA", "Fengtian");
		json = json.replaceAll("BENZ", "Benchi");
		response.setContentType("text/html;charset=UTF-8");
                
		response.getWriter().print(json);
	}

	private String readJSONStringFromRequestBody(HttpServletRequest request) {
		StringBuffer json = new StringBuffer();
		String line = null;
		try {
			BufferedReader reader = request.getReader();
			while((line = reader.readLine()) != null){
				json.append(line);
			}
		} catch (IOException e) {
			System.out.println("IOException");
			e.printStackTrace();
		}
		return json.toString();
	}

	
}
